package com.ruoyi.womp.mqhandler;

import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.womp.tools.DateUtil;

public class WompDataUtil {

	public static synchronized JSONObject getDataTableName(JSONObject messageJsonObject) throws ParseException {

		// 衡器号
		String wacode = messageJsonObject.getString("waCode").trim();
		// 数据时间
		String dataTime = messageJsonObject.getString("time");
		Date date = DateUtil.parseDate(dataTime, DateUtil.yyyyMMddHHmmss);

		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		int year = cal.get(Calendar.YEAR);
		int month = cal.get(Calendar.MONTH) + 1;

		// 分钟数据表表名
		String dataTableNameM = "WRD_" + wacode + "_M" + year;
		// 秒数据表表名
		String dataTableNameS = "WRD_" + wacode + "_S" + year + (month < 10 ? "0" + month : month);

		JSONObject resultJsonObject = new JSONObject();
		resultJsonObject.put("minuteName", dataTableNameM);
		resultJsonObject.put("secondName", dataTableNameS);

		return resultJsonObject;
	}
}
